#include <stdio.h>
#include <time.h>
#include "base.h"
#include "acofs.h"

//variar NANTS em 0.75 e 1.5
//#define NANTS 0.75
#define NELITE 0.1

//variar LS em 0 e 1
//#define LS 0
#define MINPHE 0.15
//#define MAX 50

int main(int argc, char **argv)
{
	int selected_features = 0;
    FILE *in;
	Base *b;
	Experiment *e;

	int seed = time(NULL);
	int i;

    if(argc > 4)
		seed = atoi(argv[4]);

	srandom(seed);

	in = fopen(argv[1], "r");
	if(!in)
	{
		fprintf(stderr, "fopen fail: %s\n", argv[1]);
		exit(2);
	}

	//ler base + info relacionado a importancia das caracteristicas
	b = readBase(in);
	if(!b)
	{
		fprintf(stderr, "readBase fail\n");
		exit(2);
	}

	fclose(in);

    float NANTS = atof(argv[2]);
    int LS = atoi(argv[3]);
	int MAX = atoi(argv[4]);
	// Configurar experimento base, numFormigas, tamElite, maxIteracoes, min_feromonio
	e = newExperiment(b, 1 + b->nFeatures * NANTS,  1 + b->nFeatures * NANTS * NELITE, LS, MAX, MINPHE);
	if(!e)
	{
		fprintf(stderr, "newExperiment fail\n");
		exit(2);
	}

	fprintf(stderr, "features %d, nants %d, nelite %d, buscalocal %d, max %d, minpher %f\n", \
	                b->nFeatures, e->nAnts, e->nElite, LS, MAX, MINPHE);

	optimize(e);

	fprintf(stderr, "\nSolução final: %f\n", e->bestSolF);

	for(i = 0; i < e->base->nFeatures; i++)
	{
		printf("%d", e->bestSol[i] == 1 ? 1 : 0);

        if(e->bestSol[i] == 1)
            selected_features++;
    }

	printf(" %d %d \n", selected_features, e->base->nFeatures);

}
